﻿<cfsilent>

	<cfset jsonAdvice = getProperty("serviceFactory").getBean("jsonAdvice") />
	<cfset response = structNew() />

	<cftransaction>
		<cfif event.getArg("SubjectName") neq "" AND event.getArg("SubjectShortName") neq "">
            <cfset sql = "UPDATE t_subject a 
							SET
								   a.sbj_name = :SubjectName ,
								   a.sbj_short = :SubjectShortName ,
								   a.sbj_english = :SubjectEnglish 
							WHERE a.sbj_id = :SubjectID "/>
                            
            <cfset updateObj = new Query(datasource = application.dnsMaster)/>
            <cfset updateObj.addParam(name ="SubjectName", value=event.getArg("SubjectName"), cfsqltype="cf_sql_varchar")/>
            <cfset updateObj.addParam(name ="SubjectShortName", value=event.getArg("SubjectShortName"), cfsqltype="cf_sql_varchar")/>
            <cfset updateObj.addParam(name ="SubjectEnglish", value=event.getArg("SubjectEnglish"), cfsqltype="cf_sql_varchar")/>
            <cfset updateObj.addParam(name ="SubjectID", value=event.getArg("SubjectID"), cfsqltype="cf_sql_varchar")/>
			<cfset updateObj.execute(sql = sql)/>
		</cfif>
		
		<cfset sql =  "SELECT a.sbj_id,
							   a.sbj_name,
							   a.sbj_short,
							   a.sbj_english 
						FROM t_subject a 
						WHERE a.sbj_id = :SubjectID "/>
                        
        <cfset queryObj = new query( datasource=application.dnsMaster )/>
        <cfset queryObj.addParam( name="SubjectID", value=event.getArg("SubjectID"), cfsqltype="cf_sql_varchar" )/>
        
		<cfset rs_subjects = queryObj.execute( sql=sql ).getResult()/>
		
		<cfset structInsert(response, "SubjectID", rs_subjects.sbj_id) />
		<cfset structInsert(response, "SubjectName", rs_subjects.sbj_name) />
		<cfset structInsert(response, "SubjectShortName", rs_subjects.sbj_short) />
		<cfset structInsert(response, "SubjectEnglish", rs_subjects.sbj_english) />
		
	</cftransaction>

</cfsilent><cfoutput>#jsonAdvice.encode(data:response, stringNumbers:true)#</cfoutput>